﻿using System.Collections.Generic;
using IceZero.Business;
using IceZero.Business.Models;
using IceZero.Web.Helpers;
using Microsoft.AspNetCore.Mvc;

namespace IceZero.Controllers
{
    /// <summary>
    /// 动作统计控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]/[action]")]
    [Produces("application/json")]
    [ProducesErrorResponseType(typeof(IceZeroExceptionResult))]
    public class ActionStatisticController : ControllerBase
    {
        private readonly ActionStatisticBusiness _actionStatisticBusiness;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="actionStatisticBusiness"></param>
        public ActionStatisticController(ActionStatisticBusiness actionStatisticBusiness)
        {
            _actionStatisticBusiness = actionStatisticBusiness;
        }

        /// <summary>
        /// 获取所有可用的动作组列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetActionCombos()
        {
            return ActionHelper.ExecAction(this, controller =>
            {
                return _actionStatisticBusiness.GetActionCombos();
            });
        }

        /// <summary>
        /// 获取目标统计信息
        /// </summary>
        /// <param name="args">参数对象</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetTargetStatisticInfo([FromQuery] GetTargetStatisticInfoArgs args)
        {
            return ActionHelper.ExecAction(this, controller =>
            {
                return _actionStatisticBusiness.GetTargetStatisticInfo(args);
            });

        }

        /// <summary>
        /// 批量获取目标对象的统计信息
        /// </summary>
        /// <param name="argsList">参数对象列表</param>
        [HttpPost]
        public IActionResult BatchGetTargetStatisticInfo([FromBody] List<GetTargetStatisticInfoArgs> argsList)
        {
            return ActionHelper.ExecAction(this, controller =>
            {
                return _actionStatisticBusiness.BatchGetTargetStatisticInfo(argsList);
            });

        }

        /// <summary>
        /// 获取用户主动行为统计信息
        /// </summary>
        /// <param name="userId">统计用户的id</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetUserStatisticInfo(string userId)
        {
            return ActionHelper.ExecAction(this, controller =>
            {
                return _actionStatisticBusiness.GetUserStatisticInfo(userId);
            });

        }

        /// <summary>
        /// 批量获取用户主动行为统计信息
        /// </summary>
        /// <param name="userIds">统计用户的id列表</param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult BatchGetUserStatisticInfo([FromBody] List<string> userIds)
        {
            return ActionHelper.ExecAction(this, controller =>
            {
                return _actionStatisticBusiness.BatchGetUserStatisticInfo(userIds);
            });
        }


        /// <summary>
        /// 获取目标拥有人被执行正向行为统计信息
        /// </summary>
        /// <param name="targetOwnerId">目标拥有人id</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetTargetOwnerStatisticInfo([FromQuery]string targetOwnerId = "unknown")
        {
            return ActionHelper.ExecAction(this, controller =>
            {
                return _actionStatisticBusiness.GetTargetOwnerStatisticInfo(targetOwnerId);
            });
        }

        /// <summary>
        /// 批量获取目标拥有人被执行正向行为统计信息
        /// </summary>
        /// <param name="targetOwnerIds">目标拥有人id列表</param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult BatchGetTargetOwnerStatisticInfo([FromBody] List<string> targetOwnerIds)
        {
            return ActionHelper.ExecAction(this, controller =>
            {
                return _actionStatisticBusiness.BatchGetTargetOwnerStatisticInfo(targetOwnerIds);
            });
        }


        /// <summary>
        /// 添加操作统计
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult AddOperationRecord([FromQuery] AddOperationRecordArgs args)
        {
            return ActionHelper.ExecAction(this, controller =>
            {
                _actionStatisticBusiness.AddOperationRecord(args);
            });

        }

        /// <summary>
        /// 批量添加操作统计
        /// </summary>
        /// <param name="argsList"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult BatchAddOperationRecord([FromBody] List<AddOperationRecordArgs> argsList)
        {
            return ActionHelper.ExecAction(this, controller =>
            {
                _actionStatisticBusiness.BatchAddOperationRecord(argsList);
            });
        }
    }
}
